package com.five.controller;

import com.five.pojo.Club;
import com.five.pojo.ClubJoin;
import com.five.pojo.PageBean;
import com.five.pojo.Result;
import com.five.service.ClubService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.objenesis.instantiator.sun.SunReflectionFactoryInstantiator;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lenovo
 */
@Tag(name = "社团信息接口")
@RestController
@RequestMapping("/club")
@CrossOrigin
public class ClubController {
    @Autowired
    ClubService clubService;
    //分页
    @Operation(summary = "查看本社团的所有学生(团长)")
    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String  cName , String cType)
    {
        PageBean pageBean = clubService.page(page , pageSize , cName , cType);
        return Result.success(pageBean);
    }

    //查看社团所有信息
    @Operation(summary = "查看社团所有信息")
    @GetMapping("/getClub")
    public Result getAll(){
        List<Club> clubList = clubService.getAll();
        return Result.success(clubList);
    }

    //新社团入驻娱乐天地(团长)
    @Operation(summary = "新社团入驻(团长)")
    @PostMapping("/addClub")
    public Result addClub(@RequestBody Club club){
        clubService.addClub(club);
        return Result.success();
    }

    //更新社团信息(团长)
    @Operation(summary = "更新社团信息(团长/管理员)")
    @PutMapping("/updateClub")
    public Result updateClub(@RequestBody Club club){
        clubService.updateClub(club);
        return Result.success();
    }

    //删除社团信息(只有管理员可以删除)
    @Operation(summary = "删除社团信息(管理员)")
    @DeleteMapping
    public Result deleteClub(Integer cid){
        clubService.deleteClub(cid);
        return Result.success();
    }
    //团长登录：我的社团
    @Operation(summary = "我的社团(团长)")
    @GetMapping("/getByHeader")
    public Result getByHeader(String cHeader){
        List<Club> clubHeaderList = clubService.getByHeader(cHeader);
        return Result.success(clubHeaderList);
    }
    //查询社团总数
    @Operation(summary = "查询社团总数")
    @GetMapping("/getClubTotal")
    public Result getTotal(){
        Integer total = clubService.getTotal();
        return Result.success(total);
    }

    //管理员审批团长新增的社团
    @Operation(summary = "管理员审批团长新增的社团")
    @PutMapping("/managerModStatus")
    public Result managerModStatus(Integer status , Integer cid){
        clubService.updateStatus(status , cid);
        if(status == 1){
            return Result.success(1);
        }
        return Result.success(0);
    }

}
